/**
 * 员工列表输出项
 */
interface EmployeeListItemResponse {
    /**
     * 标识符
     */
    id: string;
    /**
     * 序号
     */
    index: number;
    /**
     * 用户名
     */
    userName: string;
    /**
     * 真实姓名
     */
    realName: string;
    /**
     * 手机号
     */
    phoneNumber: string;
    /**
     * 部门
     */
    department: string;
    /**
     * 最后登录时间
     */
    lastLoginTime: string;
    /**
     * 专员类型
     */
    types: string;
}

/**
 * 员工详细
 */
interface EmployeeDetailResponse extends BaseResponse {
    /**
     * 用户名
     */
    userName: string;
    /**
     * 邮箱
     */
    email: string;
    /**
     * 手机号
     */
    phoneNumber: string;
    /**
     * 真实姓名
     */
    realName: string;
    /**
     * 性别
     */
    sex: boolean;
    /**
     * 是否启用
     */
    isEnabled: boolean;
    /**
     * 用户组编号
     */
    userGroupId: string;
    /**
     * 权限值
     */
    roles: Array<string>;
    /**
     * 专员类型
     */
    types: Array<string>;
}

/**
 * 员工权限
 */
interface EmployeeAuth {
    //高等级权限
    HighAuthNumber:number[];
    //中等级权限
    MiddleAuthNumber:number[];
    //低等级权限
    LowAuthNumber:number[];
    //二级权限标签
    SecAuthTypeTag:string[]
}

/**
 * 员工服务
 */
interface IEmployeeService {
    /**
     * 获取专员列表
     * @param type 专员类型
     * @param 跳过项数
     * @param 获取项数
     */
    getbytype(type:string,skip:number,count:number):ng.IHttpPromise<ListResponse<EmployeeListItemResponse>>;

    /**
     * 获取列表
     * v1.0
     * @param type 专员类型
     * @param userName 用户名
     * @param realName 真实姓名
     * @param phoneNumber 手机号
     * @param departmentId 所属部门
     * @param isEnabled 是否启用
     * @param skip 跳过项数
     * @param count 获取项数
     */
    getList(type: string, userName: string, realName: string, phoneNumber: string, departmentId: string, isEnabled:boolean, skip: number, count: number): ng.IHttpPromise<ListResponse<EmployeeListItemResponse>>;

    /**
     * 获取详细
     * v1.0
     * @param id 员工编号
     */
    getDetail(id: string): ng.IHttpPromise<EmployeeDetailResponse>;

    /**
     * 添加员工
     * v1.0
     * @param userName 用户名
     * @param password 密码
     * @param rePassword 重复密码
     * @param email 邮箱
     * @param phoneNumber 手机号
     * @param realName 真实姓名
     * @param sex 性别
     * @param isEnabled 是否启用
     * @param userGroupId 用户组编号
     * @param roles 权限值
     * @param types 专员类型
     */
    add(userName: string, password: string, rePassword: string, email: string, phoneNumber: string, realName: string, sex: string, isEnabled: boolean, userGroupId: string,  types: Array<string>,auth:EmployeeAuth): ng.IHttpPromise<BaseResponse>;

    /**
     * 编辑员工
     * v1.0
     * @param id 修改的员工编号
     * @param password 密码
     * @param email 邮箱
     * @param phoneNumber 手机号
     * @param realName 真实姓名
     * @param sex 性别
     * @param isEnabled 是否启用
     * @param userGroupId 用户组编号
     * @param roles 权限值
     * @param types 专员类型
     */
    edit(id: string, password: string, email: string, phoneNumber: string, realName: string, sex: string, isEnabled: boolean, userGroupId: string, types: Array<string>,auth:DepartmentAuth): ng.IHttpPromise<BaseResponse>;

    /**
     * 编辑员工权限
     */
    editAuth(id:string,body:EmployeeAuth):ng.IHttpPromise<BaseResponse>;
}

class employeeService implements IEmployeeService {
    constructor(private http: ng.IHttpService, private route: routeService) {
    }

    /**获取专员列表 */
    getbytype(type:string,skip:number,count:number):ng.IHttpPromise<ListResponse<EmployeeListItemResponse>>{
        return this.http<ListResponse<EmployeeListItemResponse>>({
            method:"GET",
            url: this.route.getUrl("employee/getbytype?type={{type}}&skip={{skip}}&count={{count}}",{
                type:type,
                skip:skip,
                count:count
            })
        })
    }

    /**获取列表 */
    getList(type: string, userName: string, realName: string, phoneNumber: string, departmentId: string, isEnabled:boolean, skip: number, count: number): ng.IHttpPromise<ListResponse<EmployeeListItemResponse>> {
        return this.http<ListResponse<EmployeeListItemResponse>>({
            method: "GET",
            url: this.route.getUrl("employee?type={{type}}&userName={{userName}}&realName={{realName}}&phoneNumber={{phoneNumber}}&departmentId={{departmentId}}&isEnabled={{isEnabled}}&skip={{skip}}&count={{count}}", {
                type: type,
                userName: userName,
                realName: realName,
                phoneNumber: phoneNumber,
                departmentId: departmentId,
                isEnabled:isEnabled,
                skip: skip,
                count: count
            })
        });
    }

    getDetail(id: string): ng.IHttpPromise<EmployeeDetailResponse> {
        return this.http<EmployeeDetailResponse>({
            method: "GET",
            url: this.route.getUrl("employee/{{id}}", {
                id: id
            })
        });
    }

    add(userName: string, password: string, rePassword: string, email: string, phoneNumber: string, realName: string, sex: string, isEnabled: boolean, userGroupId: string,  types: Array<string>,auth:EmployeeAuth): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "POST",
            url: this.route.getUrl("employee"),
            data: {
                userName: userName,
                password: password,
                rePassword: rePassword,
                email: email,
                phoneNumber: phoneNumber,
                realName: realName,
                sex: sex,
                isEnabled: isEnabled,
                userGroupId: userGroupId,
                roles: [],
                types: types,
                highAuthNumber:auth.HighAuthNumber,
                middleAuthNumber:auth.MiddleAuthNumber,
                lowAuthNumber:auth.LowAuthNumber,
                SecAuthTypeTag:auth.SecAuthTypeTag
            }
        });
    }

    edit(id: string, password: string, email: string, phoneNumber: string, realName: string, sex: string, isEnabled: boolean, userGroupId: string, types: Array<string>,auth:EmployeeAuth): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "PUT",
            url: this.route.getUrl("employee/{{id}}", {
                id: id
            }),
            data: {
                password: password,
                email: email,
                phoneNumber: phoneNumber,
                realName: realName,
                sex: sex,
                isEnabled: isEnabled,
                userGroupId: userGroupId,
                roles: [],
                types: types,
                highAuthNumber:auth.HighAuthNumber,
                middleAuthNumber:auth.MiddleAuthNumber,
                lowAuthNumber:auth.LowAuthNumber,
                SecAuthTypeTag:auth.SecAuthTypeTag
            }
        });
    }

    editAuth(id:string,body:EmployeeAuth):ng.IHttpPromise<BaseResponse>{
        return this.http<BaseResponse>({
            method:"PUT",
            url:this.route.getUrl("employee/SaveEmployeeAuth?id={{id}}",{id:id}),
            data:body
        })
    }
}

angular.module('employeeService',[]).service("employeeService", ['$http', 'routeService', employeeService]);